package manage.util;

import manage.model.User;
import manage.model.Userinfo;

import java.util.*;

public class userChart {
    public static List getChart(String ss,List<Userinfo> list){
        List l1 = new ArrayList();

        l1.add(userChart.get1(ss,list));
        l1.add(userChart.get2(ss,list));
        l1.add(userChart.get3(ss,list));
        l1.add(userChart.get4(ss,list));
        if(ss.equals("全体员工")){
            l1.add(userChart.get0(list));
        }
        return l1;
    }

    public static Map get0(List<Userinfo> list){
        Map m2 = new HashMap();
        m2.put("title", "人员统计");

        TreeMap<String, Integer> tm = new TreeMap<String, Integer>();
        for (Userinfo user: list) {
            Integer i = tm.get(user.getDepnumber());
            if(i == null){
                tm.put(user.getDepnumber(), 1);
            }else {
                i++;
                tm.put(user.getDepnumber(),i);
            }
        }

        Set<String> arr=tm.keySet();
        List list1 = new ArrayList();
        List list2 = new ArrayList();
        for (String a:arr) {
            list1.add(a);
            list2.add(tm.get(a));
        }
        m2.put("aa",list1);
        m2.put("bb",list2);

        return m2;
    }

    public static Map get1(String ss,List<Userinfo> list){
        Map m2 = new HashMap();
        m2.put("title",ss+ "职称统计");

        TreeMap<String, Integer> tm = new TreeMap<String, Integer>();
        for (Userinfo user: list) {
            Integer i = tm.get(user.getGangwei());
            if(i == null){
                tm.put(user.getGangwei(), 1);
            }else {
                i++;
                tm.put(user.getGangwei(),i);
            }
        }

        Set<String> arr=tm.keySet();
        List list1 = new ArrayList();
        List list2 = new ArrayList();
        for (String a:arr) {
            list1.add(a);
            list2.add(tm.get(a));
        }
        m2.put("aa",list1);
        m2.put("bb",list2);

        return m2;
    }
    public static Map get2(String ss,List<Userinfo> list){
        Map m2 = new HashMap();
        m2.put("title", ss+"职位统计");

        TreeMap<String, Integer> tm = new TreeMap<String, Integer>();
        for (Userinfo user: list) {
            Integer i = tm.get(user.getJob());
            if(i == null){
                tm.put(user.getJob(), 1);
            }else {
                i++;
                tm.put(user.getJob(),i);
            }
        }

        Set<String> arr=tm.keySet();
        List list1 = new ArrayList();
        List list2 = new ArrayList();
        for (String a:arr) {
            list1.add(a);
            list2.add(tm.get(a));
        }
        m2.put("aa",list1);
        m2.put("bb",list2);

        return m2;
    }
    public static Map get3(String ss,List<Userinfo> list){
        Map m2 = new HashMap();

        m2.put("title", ss+"学历统计");

        TreeMap<String, Integer> tm = new TreeMap<String, Integer>();
        for (Userinfo user: list) {
            Integer i = tm.get(user.getEducation());
            if(i == null){
                tm.put(user.getEducation(), 1);
            }else {
                i++;
                tm.put(user.getEducation(),i);
            }
        }

        Set<String> arr=tm.keySet();
        List list1 = new ArrayList();
        List list2 = new ArrayList();
        for (String a:arr) {
            list1.add(a);
            list2.add(tm.get(a));
        }
        m2.put("aa",list1);
        m2.put("bb",list2);

        return m2;
    }

    public static Map get4(String ss,List<Userinfo> list){
        Map m2 = new HashMap();
        m2.put("title", ss+"男女比例");

        TreeMap<String, Integer> tm = new TreeMap<String, Integer>();
        int size = list.size();
        int man = 0;
        for (Userinfo user: list) {
            if(user.getSex().equals("男"))
                man++;
        }
        int woman = size-man;
        List list1 = new ArrayList();
        Map map = new HashMap();
        map.put("name","男"+man);
        map.put("value",man);
        Map map2 = new HashMap();
        map2.put("name","女"+woman);
        map2.put("value",woman);
        list1.add(map);
        list1.add(map2);
        m2.put("data",list1);
        return m2;
    }
}
